#include "texture.h"

texture::texture()
{
	isValid = false;
	X = 0;
	Y = 0;
}
texture::texture(const char* name)
{
	textureImage = new picture();
	if(textureImage->readBMP(name))
	{
		X = textureImage->getX();
		Y = textureImage->getY();
		isValid = true;
	}
	else
	{
		isValid = false;
		X = 0;
		Y = 0;
	}
}
texture::~texture()
{

}
bool texture::created()
{
	return isValid;
}
color texture::getColor(texcoords texCoords)
{
	return textureImage->getPixel( X - (int)( ( (double)X - 1.0) * texCoords.getU()), Y - (int)(((double)Y-1.0)*texCoords.getV()));
}
unsigned int texture::getX()
{
	return X;
}
unsigned int texture::getY()
{
	return Y;
}
double texture::getRatio()
{
	if(Y!=0.0)
		return (double)X/(double)Y;
	else
		return 0;
}